package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzCountOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

@Service
public class ReportServiceImpl implements ReportService {


     @Autowired
    private EmpMapper empMapper;

     @Autowired
     private StudentMapper studentMapper;

     /**
     * 获取员工职位分布数据
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
        //1. 调用mapper接口，获取统计数据
        List<Map<String,Object>> list = empMapper.countEmpJobData();// map: pos=教研主管,num=1

        //2.组装结果，并返回
        List<Object> jobList = list.stream().map(map -> map.get("pos")).toList();
        List<Object> dataList = list.stream().map(map -> map.get("num")).toList();

        return new JobOption(jobList, dataList);

    }


    /**
     * 获取员工性别分布数据
     * @return
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }


    /**
     * 获取学员学历分布数据
     * @return
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    @Override
    public ClazzCountOption getStudentCountData() {
        List<Map<String, Object>> countList = studentMapper.getStudentCount();
        if (!CollectionUtils.isEmpty(countList)){//判断集合是否为空和null
            List<Object> clazzList = countList.stream().map(map -> map.get("cname")).toList();
            List<Object> dateList = countList.stream().map(map -> map.get("scount")).toList();
            return new ClazzCountOption(clazzList, dateList);
        }
        return null;

    }
}
